
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')

var sys = require('util');
var OAuth= require('oauth').OAuth;

oa= new OAuth("https://api.dropbox.com/1/oauth/request_token",
                 "https://api.dropbox.com/1/oauth/access_token", 
                 "0fpr1qt5s6byefw", "ku4cerwygc1mgq0", 
                 "1.0", "http://localhost:3000/oauth/callback", "HMAC-SHA1");

var app = module.exports = express.createServer();



// var oa = new OAuth(
// 	"https://api.twitter.com/oauth/request_token",
// 	"https://api.twitter.com/oauth/access_token",
// 	"YourConsumerKeyProvidedByTwitter",
// 	"YourConsumerSecretProvidedByTwitter",
// 	"1.0",
// 	"http://yourdomain/auth/twitter/callback",
// 	"HMAC-SHA1"
// );

// Configuration

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(express.session({ secret: "keyboard cat" }));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
});

app.configure('production', function(){
  app.use(express.errorHandler()); 
});

// Routes

app.get('/', routes.index);

app.get('/auth/firedrop', function(req, res){
	oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){
		if (error) {
			console.log(res);
			console.log(error);
			res.send("yeah no. didn't work.")
		}
		else {
			req.session.oauth = {};
			req.session.oauth.token = oauth_token;
			console.log('oauth.token: ' + req.session.oauth.token);
			req.session.oauth.token_secret = oauth_token_secret;
			console.log('oauth.token_secret: ' + req.session.oauth.token_secret);
			res.redirect('https://www.dropbox.com/1/oauth/authorize?oauth_token='+oauth_token+'&oauth_callback=' + 'http://cobweb.seas.gwu.edu/~cma27')
	}
	});
});

var port = process.env.PORT || 3000;
app.listen(port, function() {
  console.log("Listening on " + port);
});
